home *** CD-ROM | disk | FTP | other *** search
/ InterCD 1999 March / marchl_1999.iso / Site Building / Mallsurfer Shop / _SETUP.1 / invoice_custom.txt < prev    next >
Encoding:
Text File  |  1998-07-22  |  8.8 KB  |  266 lines

  1.  
  2. <script language="JavaScript">
  3.  
  4. MaxCartItems = 15;
  5.  
  6. function getCookieVal (offset) {
  7.   var endstr = document.cookie.indexOf (";", offset);
  8.   if (endstr == -1)
  9.     endstr = document.cookie.length;
  10.   return unescape(document.cookie.substring(offset, endstr));
  11. }
  12.  
  13. function GetCookie (name) {
  14.   var arg = name + "=";
  15.   var alen = arg.length;
  16.   var clen = document.cookie.length;
  17.   var i = 0;
  18.   while (i < clen) {
  19.     var j = i + alen;
  20.        if (document.cookie.substring(i, j) == arg)
  21.      return getCookieVal (j);
  22.     i = document.cookie.indexOf(" ", i) + 1;
  23.     if (i == 0) break; 
  24.   }
  25.   return null;
  26. }
  27.  
  28. function SetCookie (name, value) {
  29.   var argv = SetCookie.arguments;
  30.   var argc = SetCookie.arguments.length;
  31.   var expires = (argc > 2) ? argv[2] : null;
  32.   var path = (argc > 3) ? argv[3] : null;
  33.   var domain = (argc > 4) ? argv[4] : null;
  34.   var secure = (argc > 5) ? argv[5] : false;
  35.   document.cookie = name + "=" + escape (value) +
  36.     ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
  37.     ((path == null) ? "" : ("; path=" + path)) +
  38.     ((domain == null) ? "" : ("; domain=" + domain)) +
  39.     ((secure == true) ? "; secure" : "");
  40. }
  41.  
  42. function DeleteCookie (name) {
  43.   var exp = new Date();
  44.   exp.setTime (exp.getTime() - 1);  // This cookie is history
  45.   var cval = GetCookie (name);
  46.   if (cval != null)
  47.     document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
  48. }
  49.  
  50. function ShowInvoice() 
  51. {
  52.     totprice = 0;
  53.     itemlist = 0;
  54.     TotQty = 0;
  55.     TotWeight = 0;
  56.     FinalTotWeight = 0;
  57.  
  58.  
  59.     document.writeln('<table border=2 cellspacing=5 cellpadding=5>');
  60.     document.writeln('<tr><td align=center><b>ID</b></td><td align=center><b>Description</b></td><td align=center><b>Qty</b></td><td align=center><b>Weight</b></td><td align=center><b>Price Each</b></td><td align=center><b>Price Total</b></td><td align=center><b>Comments</b></td></tr>');
  61.  
  62.     for(NumItems = 0; NumItems<MaxCartItems; NumItems++)
  63.     {
  64.         CookieName = "Cart" +NumItems;
  65.         CookieValue = GetCookie(CookieName);
  66.  
  67.         if(CookieValue != null)
  68.         {
  69.             for(var i = 0;i <= CookieValue.length; i++)
  70.             {
  71.                 // using 0192,0193,0194,0195,0196
  72.                 if (CookieValue.substring(i,i+1) == '[') 
  73.                 {
  74.                     itemstart = i+1;
  75.                 } 
  76.                 else if (CookieValue.substring(i,i+1) == '└') 
  77.                 {
  78.                     ID = CookieValue.substring(itemstart, i);
  79.                     itemstart = i+1;
  80.                 } 
  81.                 else if (CookieValue.substring(i,i+1) == '┴') 
  82.                 {
  83.                     Sdesc = CookieValue.substring(itemstart, i);
  84.                     itemstart = i+1;
  85.                 }
  86.                 else if (CookieValue.substring(i,i+1) == '┬') 
  87.                 {
  88.                     Price = CookieValue.substring(itemstart, i);
  89.                     itemstart = i+1;
  90.                 }
  91.                 else if (CookieValue.substring(i,i+1) == '├') 
  92.                 {
  93.                     Qty = CookieValue.substring(itemstart, i);
  94.                     itemstart=i+1;
  95.                 } 
  96.                 else if (CookieValue.substring(i,i+1) == '─') 
  97.                 {
  98.                     Weight = CookieValue.substring(itemstart, i);
  99.                     itemstart = i+1;
  100.                 }
  101.                 else if (CookieValue.substring(i,i+1) == ']') 
  102.                 {
  103.                     WeightUnit = CookieValue.substring(itemstart, i);
  104.                     itemstart = i+1;
  105.  
  106.                     TotQty = TotQty + parseInt(Qty);
  107.                     TotWeight = Weight * Qty;
  108.  
  109.                     ItemTotal = 0;
  110.                     ItemTotal = (eval(Price*Qty));
  111.                     temptotal = ItemTotal * 100;
  112.                     totprice = totprice + ItemTotal;
  113.  
  114.                     FItemTotal = FloatFormat(ItemTotal,2);
  115.                     FTotWeight = FloatFormat(TotWeight,2);
  116.  
  117.                     ConvertUnit(TotWeight,WeightUnit,'lbs');
  118.                     ConvertedWeight = NewUnitSize;
  119.                     FinalTotWeight = FinalTotWeight + NewUnitSize;
  120.                     FConvertedWeight = FloatFormat(ConvertedWeight,2);
  121.             document.writeln('<input type=hidden name="Item" value="------------------------------------------------------------------------">');
  122.             document.writeln('<input type=hidden name="ID" value="'+ID+'">');
  123.             document.writeln('<input type=hidden name="Description" value="'+Sdesc+'">');
  124.             document.writeln('<input type=hidden name="Qty" value="'+Qty+'">');
  125.             document.writeln('<input type=hidden name="Price Each" value="'+Price+'">');
  126.             document.writeln('<input type=hidden name="Total Price '+Qty+' items(s)" value="'+FItemTotal+'">');
  127.             document.writeln('<tr><td>'+ID+'</td><td>'+Sdesc+'</td><td align=right>'+Qty+'</td><td align=right>'+FTotWeight+' '+WeightUnit+' = '+FConvertedWeight+' lbs</td><td align=right>'+Price+'</td><td align=right>'+FItemTotal+'</td><td><input type=text name="Comments" size=10></td></tr>');
  128.     document.writeln('<input type=hidden name="Weight" value="'+FTotWeight+' '+WeightUnit+'">');
  129.     document.writeln('<input type=hidden name="Weight Converted to lbs" value="'+FConvertedWeight+'">');
  130.                 }
  131.             }
  132.         }
  133.     }
  134.  
  135.     Ftotprice = FloatFormat(totprice,2);
  136.     document.writeln('<input type=hidden name="Totals" value="------------------------------------------------------------------------">');
  137.     document.writeln('<tr><td colspan=5><b>Sub Total</b></td><td align=right>'+Ftotprice+'</td></tr>');
  138.     document.writeln('<input type=hidden name="Sub Total" value="'+Ftotprice+'">');
  139.  
  140.     Tax = totprice * 7.250000;
  141.     CTax = 0;
  142.     FTax = FloatFormat(Tax,2);
  143.     FCTax = FloatFormat(CTax,2);
  144.     OCShipping = 0;
  145.     Shipping = 0;
  146.  
  147.     if(FinalTotWeight >= 0.01 && FinalTotWeight >= 1)
  148.     {
  149.         Shipping = 3.50;
  150.         TmpFinalTotWeight = FinalTotWeight - 1;
  151.         TmpFinalTotWeight = TmpFinalTotWeight / 1;
  152.         TmpFinalTotWeight = TmpFinalTotWeight * 0.35;
  153.         Shipping = TmpFinalTotWeight + Shipping;
  154.     }
  155.  
  156.     else if(FinalTotWeight >= 0.01 && FinalTotWeight <= 1)
  157.         Shipping = 3.50;
  158.  
  159.     FShipping = FloatFormat(Shipping,2);
  160.     FOCShipping = FloatFormat(OCShipping,2);
  161.     FFinalTotWeight = FloatFormat(FinalTotWeight,2);
  162.     document.writeln('<tr><td colspan=3><b>lbs</b></td><td align=right>'+FFinalTotWeight+' Total Weight</td></tr>');
  163.     document.writeln('<input type=hidden name="lbs" value="'+FFinalTotWeight+' Total Weight">');
  164.     document.writeln('<tr><td colspan=5><b>Shipping</b></td><td align=right>'+FShipping+'</td></tr>');
  165.     document.writeln('<input type=hidden name="Shipping" value="'+FShipping+'">');
  166.  
  167.     NatFGrandTotal = FloatFormat(totprice + CTax + Shipping,2);
  168.     ONatFGrandTotal = FloatFormat(totprice + Shipping + OCShipping,2);
  169.     FGrandTotal = FloatFormat(totprice + Tax + CTax + Shipping,2);
  170.     document.writeln('<tr><td colspan=5><b>Tx Sales Tax</b></td><td align=right>'+FTax+'</td></tr>');
  171.     document.writeln('<input type=hidden name="Tx Sales Tax" value="'+FTax+'">');
  172.     document.writeln('<tr><td colspan=5><b><font color=red>Total for Non-Tx residents in USA</font></b></td><td align=right><font color=red>$ '+NatFGrandTotal+'</font></td></tr>');
  173.     document.writeln('<input type=hidden name="Total for Non-Tx residents in USA" value="$ '+NatFGrandTotal+'">');
  174.     document.writeln('<tr><td colspan=5><b><font color=red>Total for Tx residents</font></b></td><td align=right><font color=red>$ '+FGrandTotal+'</font></td></tr>');
  175.     document.writeln('<input type=hidden name="Total for Tx residents" value="$ '+FGrandTotal+'">');
  176.     document.writeln('<tr><td colspan=5><b><font color=red>Total for sales outside of USA</font></b></td><td align=right><font color=red>$ '+ONatFGrandTotal+'</font></td></tr>');
  177.     document.writeln('<input type=hidden name="Total for sales outside of USA" value="$ '+ONatFGrandTotal+'">');
  178.     document.writeln('</table>');
  179. }
  180.  
  181. function FloatFormat(expr,decplaces)
  182. {
  183.     var str = "" + Math.round(eval(expr) * Math.pow(10,decplaces));
  184.     while(str.length <= decplaces)
  185.     {
  186.         str = "0" + str;
  187.     }
  188.  
  189.     var decpoint = str.length - decplaces;
  190.     return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
  191. }
  192.  
  193. rsize = 10;        // rounding size
  194. oz_factor = 1;        // ounces to ounces
  195. lbs_factor = 0.0625;        // ounces to pounds
  196. mg_factor = 28349.5;        // ounces to miligrams
  197. g_factor = 28.3495;        // ounces to grams
  198. kg_factor = .0283495;    // ounces to kilograms
  199. var UnitSize;    // weight number being converted
  200. var OldUnit;    // converting from
  201. var NewUnit;    // converting to
  202. var NewUnitSize;    // new weight in new unit
  203.  
  204. function ConvertUnit(UnitSize,OldUnit,NewUnit)
  205. {
  206. // possible units
  207. // oz
  208. // lbs
  209. // mg
  210. // g
  211. // kg
  212.  
  213.     NewUnitSize = 0;
  214.     TmpUnitSize = 0;
  215.  
  216.     // if not oz, convert to oz first
  217.     if(OldUnit != 'oz')
  218.     {
  219.         if(OldUnit == 'lbs')
  220.         {
  221.             TmpUnitSize = UnitSize / lbs_factor;
  222.         }
  223.         else if(OldUnit == 'mg')
  224.         {
  225.             TmpUnitSize = UnitSize / mg_factor; 
  226.         }
  227.         else if(OldUnit == 'g')
  228.         {
  229.             TmpUnitSize = UnitSize / g_factor; 
  230.         }
  231.         else if(OldUnit == 'kg')
  232.         {
  233.             TmpUnitSize = UnitSize / kg_factor; 
  234.         }
  235.     }
  236.     else
  237.     {
  238.         // if oz, keep as is
  239.         TmpUnitSize = UnitSize;
  240.     }
  241.  
  242.     // since TmpUnitSize is now oz, convert to NewUnit;
  243.     if(NewUnit == 'oz')
  244.     {
  245.         NewUnitSize = TmpUnitSize;
  246.     }
  247.     else if(NewUnit == 'lbs')
  248.     {
  249.         NewUnitSize = TmpUnitSize * lbs_factor;
  250.     }
  251.     else if(NewUnit == 'mg')
  252.     {
  253.         NewUnitSize = TmpUnitSize * mg_factor;
  254.     }    
  255.     else if(NewUnit == 'g')
  256.     {
  257.         NewUnitSize = TmpUnitSize * g_factor;
  258.     }    
  259.     else if(NewUnit == 'kg')
  260.     {
  261.         NewUnitSize = TmpUnitSize * kg_factor;
  262.     }    
  263. }
  264.  
  265. </script>
  266.